package cn.anecansaitin.whimsy.common.effect;

import cn.anecansaitin.whimsy.Whimsy;
import cn.anecansaitin.whimsy.common.register.ModEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.entity.living.LivingEvent;

@Mod.EventBusSubscriber(modid = Whimsy.MODID)
public class CommonEarthquakeEvent {
    @SubscribeEvent
    public static void jump(LivingEvent.LivingJumpEvent event) {
        //史莱姆的跳跃比较特殊，不会触发这个事件
        LivingEntity entity = event.getEntity();

        if (!entity.hasEffect(ModEffects.EARTHQUAKE.get())) {
            return;
        }

        int amplifier = entity.getEffect(ModEffects.EARTHQUAKE.get()).getAmplifier() + 1;
        amplifier = Math.min(amplifier, 3);
        Vec3 delta = entity.getDeltaMovement();
        entity.setDeltaMovement(delta.x, (0.6 - amplifier * 0.2) * delta.y, delta.z);
    }
}
